import { defHttp } from '@/utils/http/axios';
import {
  SiteInfo,
  SiteParams,
  SiteListGetResultModel,
  SiteAddReq,
  SiteEditReq,
  SiteDelReq,
} from './model/siteModel';

enum Api {
  List = '/api/admin/v1/site/list',
  Create = '/api/admin/v1/site/add',
  Update = '/api/admin/v1/site/edit',
  Delete = '/api/admin/v1/site/del',
  Info = '/api/admin/v1/site/info',
  TemplateList = '/api/admin/v1/template/list',
  ServerList = '/api/admin/v1/servers/list',
}

/**
 * @description: 获取站点列表
 */
export const getSiteList = (params: SiteParams) =>
  defHttp.get<SiteListGetResultModel>({
    url: Api.List,
    params,
    headers: { 'Content-Type': 'multipart/form-data' },
  });

/**
 * @description: 创建站点
 */
export const createSite = (params: SiteAddReq) =>
  defHttp.post<{ id: number }>({ url: Api.Create, params });

/**
 * @description: 更新站点
 */
export const updateSite = (params: SiteEditReq) => defHttp.put<void>({ url: Api.Update, params });

/**
 * @description: 删除站点
 */
export const deleteSite = (params: SiteDelReq) => defHttp.delete<void>({ url: Api.Delete, params });

/**
 * @description: 获取站点详情
 */
export const getSiteInfo = (id: number) => defHttp.get<SiteInfo>({ url: Api.Info, params: { id } });

/**
 * @description: 获取模板列表
 */
export const getTemplateList = (params?: { name?: string; status?: number }) =>
  defHttp.get({
    url: Api.TemplateList,
    params: { ...params, page: 1, size: 100 },
    headers: { 'Content-Type': 'multipart/form-data' },
  });

/**
 * @description: 获取服务器列表
 */
export const getServerList = (params?: { name?: string; status?: number }) =>
  defHttp.get({
    url: Api.ServerList,
    params: { ...params, page: 1, size: 100 },
    headers: { 'Content-Type': 'multipart/form-data' },
  });
